package com.prs.crm.dao.cqunicom.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cqunicom.NewsSendPersonDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cqunicom.NewsSendPerson;
import com.prs.crm.domain.cqunicom.PoplarOrder;
import com.prs.crm.domain.hr.Person;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2011-3-11 上午09:59:45
 * 简单说明
 */

public class NewsSendPersonDaoImpl extends BaseDaoImpl<NewsSendPerson>
		implements NewsSendPersonDao {

	@Override
	public Integer delNewsSendPerson() {
		return (Integer) this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
							Query query = session.createQuery("delete from NewsSendPerson");
							return query.executeUpdate();
				        }   
				 } );
	}

	@Override
	public List<NewsSendPerson> getByPersonA(final Person person) {
		return (List<NewsSendPerson>) this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(NewsSendPerson.class);
			        	criteria.add(Restrictions.eq("persons",person));	//收件人			        	
						return criteria.list();
			 				        	
			        }
				}
		);
	}

	@Override
	public List<NewsSendPerson> getByPersonB(final Person person) {
		return (List<NewsSendPerson>) this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(NewsSendPerson.class);
			        	criteria.add(Restrictions.eq("personn",person));	//发件人			        	
						return criteria.list();
			 				        	
			        }
				}
		);
	}

	@Override
	public List<NewsSendPerson> getByPersonA(final Person person, String readMark) {
		// TODO Auto-generated method stub
		return (List<NewsSendPerson>) this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(NewsSendPerson.class);
			        	criteria.add(Restrictions.eq("persons",person));	//收件人	
			        	criteria.add(Restrictions.eq("readMark","否"));
						return criteria.list();
			 				        	
			        }
				}
		);
	}

}
